package otheri.comm;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import otheri.io.Input;
import otheri.io.Output;
import android.content.Context;
import android.os.Environment;

public class FileHelper {

	private static String SDPATH;
	private static String DATAPATH;

	static {
		SDPATH = Environment.getExternalStorageDirectory().getPath();
		DATAPATH = Environment.getDataDirectory().getPath();
	}

	/*
	 * 将文件写入sd卡。如:writeSDFile("/test.txt");
	 */
	public static Output writeSDFile(String fileName) throws IOException {
		File file = new File(SDPATH + fileName);
		FileOutputStream fos = new FileOutputStream(file);
		return new Output(fos);
	}

	/*
	 * 将文件写入files目录。如:writeFile("/test.txt");
	 */
	public static Output wirteFile(Context context, String fileName)
			throws IOException {
		OutputStream os = context.openFileOutput(DATAPATH + fileName,
				Context.MODE_WORLD_WRITEABLE);
		return new Output(os);
	}

	/*
	 * 从SD卡读取文件。如:readSDFile("/test.txt");
	 */
	public static Input readSDFile(String fileName) throws IOException {
		File file = new File(SDPATH + fileName);
		FileInputStream fis = new FileInputStream(file);
		return new Input(fis);
	}

	public static Input readFile(String fileName) {
		return null;
	}
}
